#pragma once

#include "../alloc.h"

namespace sfc::io {

struct Error {
  enum Kind {
    NotFound,
    PermissionDenied,
    ConnectionRefused,
    ConnectionReset,
    ConnectionAborted,
    NotConnected,
    AddrInUse,
    AddrNotAvailable,
    BrokenPipe,
    AlreadyExists,
    WouldBlock,
    InvalidInput,
    InvalidData,
    TimedOut,
    WriteZero,
    Interrupted,
    UnexpectedEof,
    Other,
  };
  Kind kind;

  Error(Kind kind) noexcept : kind{kind} {}

  static auto from_os_error(int e) -> Error;
  static auto last_os_error() -> Error;

  auto to_str() const -> Str;

  template <class W>
  void format(fmt::Formatter<W>& f) const {
    f.write(this->to_str());
  }
};

}  // namespace sfc::io
